/*
The MIT License (MIT)

Copyright (c) 2013 Mike Dapiran, Brian May, Richard Pospesel, and Bert Wierenga

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software 
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#pragma once

#include "Hogshead.Common.h"
#include "Hogshead.Core.h"

#include "ConstantBuffer.h"

namespace Hogshead
{
	namespace DX11Rendering
	{
		//class ConstantBuffer;
		class ConstantBufferModifier;
		/*
		* Container that will hold the constant buffer list for a renderable component.
		* It is responsible for parsing and creating each ConstantBuffer.
		*
		* @see ConstantBuffer
		* @see ConstantBufferModifier
		*
		* @author Bert Wierenga
		*/
		class ConstantBufferGroup 
		{
			friend class MeshProcess;
		public:
			ConstantBufferGroup(void);
			~ConstantBufferGroup(void);

			ConstantBufferGroup(const ConstantBufferGroup& in_other);
			ConstantBufferGroup& operator=(const ConstantBufferGroup& in_other);

			/*
			* This is to be called by any components that wants to store this class.
			* This is used to parse some xml and create the ConstantBuffer's
			* this class internalizes.
			*/
			void readXML(const String& in_xml);

			/*
			* @return Returns the number of ConstantBuffer's stored.
			*/
			int size() const;

			/*
			* Used to index into the ConstantBuffer's stored.
			*
			* @param index The index to retrieve from. No error checking.
			*
			* @return Returns a pointer to the requested ConstantBuffer.
			*/
			const ConstantBuffer& get(int index) const;

			/*
			* Used to index into the ConstantBuffer's stored.
			*
			* @param index The index to retrieve from. No error checking.
			*
			* @return Returns a pointer to the requested ConstantBuffer.
			*/
			ConstantBuffer& get(int index);

			/*
			* This function can be used by any Component that needs a ConstantBufferModifier
			* to be handled.
			*
			* @param in_cbm The ConstantBufferModifier that needs to be handled.
			*/
			void handleConstantBufferModifier(const ConstantBufferModifier* in_cbm);
			
			/*
			* This will clear out all information and release acquired memory.
			* NOTE:	  This must be called by all Components using this class when they are
			* finalized!
			*/
			void clear();

		private:
			//this vector stores what we need to map a group of cbuffer's
			Vector<ConstantBuffer> _constant_buffers;

			void copyFromModifier(ConstantBuffer& destination, const ConstantBufferModifier* source);
			
			
		};

	}
}